//
//  BaseFormViewController.m
//  GoldOperationClient
//
//  Created by yaxue wang on 16/8/4.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "BaseFormViewController.h"

@interface BaseFormViewController ()

@end

@implementation BaseFormViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)initView{
    [super initView];
    
    self.mainView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [self.view addSubview:self.mainView];
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.with.bottom.equalTo(self.view);
        make.top.equalTo(self.navBar.mas_bottom);
    }];
    [self.mainView setDelegate:self];
    [self.mainView setDataSource:self];
}

- (void)initData{
    [super initData];
    self.mainData = [NSMutableArray array];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [tableView numberOfSections] > 1 ? [self.mainData[section] count] : self.mainData.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return .01;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellID"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    NSDictionary *dic = [tableView numberOfSections] > 1 ? self.mainData[indexPath.section][indexPath.row] : self.mainData[indexPath.row];
    if (![dic isKindOfClass:[NSDictionary class]]) {
        return cell;
    }
    [cell.textLabel setText:dic[@"title"]];
    [cell.textLabel setFont:F(14)];
    UIView *view = dic[@"view"];
    if (view) {
        [cell addSubview:view];
        [view setCenter:CGPointMake(107 + view.frame.size.width / 2, cell.frame.size.height / 2)];
    }
    return cell;
}

@end
